function Food(el){
    this.el=el
    this.len=20
    this.foodobj=null
    this.foodX=0
    this.foodY=0



}
Food.prototype.create=function(){
    //创建食物
    let divobj=document.createElement('div')
    //设置食物样式
    divobj.style.width=this.len+'px'
    divobj.style.height=this.len+'px'
    divobj.style.background='green'
    divobj.style.position='absolute'
    this.el.appendChild(divobj)
    // console.log(divobj.style.width);
    //默认移动食物
    this.foodobj=divobj
    this.move()

}
Food.prototype.move=function(){
    //打开页面 食物位置不一样
    let foodXMaxNum=this.el.clientWidth/this.len-1  
    let foodYMaxNum=this.el.clientHeight/this.len-1
    //随机公式
    //Math.floor(随机数*(max-min+1)+min)
    //坐标=随机个数*每个宽度
    this.foodX=Math.floor(Math.random()*(foodXMaxNum-0+1)+0)*this.len
    this.foodY=Math.floor(Math.random()*(foodYMaxNum-0+1)+0)*this.len
    // console.log(this.foodX,this.foodY);
    // console.log("this",this);
    // console.log("this.foodobj",this.foodobj);
    this.foodobj.style.left=this.foodX+'px'
    this.foodobj.style.top=this.foodY+'px'
}